home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include "/global/userwindow.h"
- #include "/global/egslibraries.h"
-
- #include <egs/egsintui.h>
- #include <egs/clib/egsintui_protos.h>
- #include <egs/pragmas/egsintui_pragmas.h>
- #include <egs/egsgadbox.h>
- #include <egs/clib/egsgadbox_protos.h>
- #include <egs/pragmas/egsgadbox_pragmas.h>
- #include <egs/egsgfx.h>
- #include <egs/clib/egsgfx_protos.h>
- #include <egs/pragmas/egsgfx_pragmas.h>
-
-
- #define TESTING_ID 200
-
- #define PROJECT_BASE_ID 500
- #define EXCLUDE_BASE_ID 600
-
- struct UserInputWindow Example_Request;
- EG_EFontPtr MenuFont=NULL; // Menu Font.
- EI_MenuPtr ExampleMenus=NULL; // Menu Pointer.
-
- BYTE Open_Menus (void);
- void Close_Menus (void);
- EI_MenuPtr InitExampleMenus (EG_EFontPtr font);
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
- void Menu_Example (UserInputWindowPtr UserWindow, UWORD code);
-
- void ToggleGhost_Menu_Item (long code);
- void UnGhost_Menu_Item (long code);
- void Ghost_Menu_Item (long code);
-
-
- void main (void) {
-
- if (OpenEGSLibraries ()) {
- if (Open_Menus ()) {
- Init_UserWindow (&Example_Request, "Example Window",WINDOW_MODAL,ExampleMenus,
- NULL);
- Example_Request.Create = Create_Example;
- Example_Request.GadgetDown = GadgetDown_Example;
- Example_Request.Menu = Menu_Example;
-
- Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
- EI_iNEWSIZE | EI_iGADGETDOWN |
- EI_iMENUPICK;
- Example_Request.Flags = EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH |
- EI_GIMMEZEROZERO ;
- Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG;
-
- if (Open_UserWindow (&Example_Request,-1,-1)) {
- Close_UserWindow (&Example_Request);
- }
- else {
- printf ("Couldn't open my window!\n");
- }
- Close_Menus ();
- }
- else {
- printf ("Couldn't open Menus for Example.\n");
- }
- }
- CloseEGSLibraries (); // after the bracket cause what if I opened 3 but
- // couldn't find the rest, still need to close the 3.
- }
-
- /*******************************
- PUBLIC: Open_Menus.
- This routine opens our menus.
- *******************************/
- BYTE Open_Menus (void) {
- ExampleMenus=NULL;
- if (!(ExampleMenus= InitExampleMenus (MenuFont))) {
- printf ("Could not Initialize Menus!\n");
- return (0);
- }
- return (1);
- }
-
-
- /******************************
- PUBLIC: Close_Menus.
- This routine closes the menus.
- *******************************/
- void Close_Menus (void) {
-
- if (ExampleMenus) {
- EI_FreeMenu (ExampleMenus);
- ExampleMenus=NULL;
- }
- if (MenuFont) {
- EG_CloseFont (MenuFont);
- MenuFont=NULL;
- }
- }
-
-
- EI_MenuPtr InitExampleMenus (EG_EFontPtr font) {
- EI_MenuPtr menu;
- EI_MenuItemPtr item1, tempitem;
- struct TextAttr *attr;
-
- if (font==NULL) {
- attr = (struct TextAttr *) EI_GetPrefFont (1);
- font = (EG_EFontPtr) EG_OpenFont (attr);
- }
-
- if (menu=EI_CreateMenu ()) {
- item1 = EI_CreateItem (font,"Project",PROJECT_BASE_ID,0,0);
- EI_AddToItem (item1,EI_CreateLeave ());
- EI_AddToItem (item1,EI_CreateItem (font,"Open...",PROJECT_BASE_ID+1,0,0));
- EI_AddToItem (item1,EI_CreateItem (font,"Save",PROJECT_BASE_ID+2,0,0));
- EI_AddToItem (item1,EI_CreateItem (font,"Save as...",PROJECT_BASE_ID+3,0,0));
- EI_AddToItem (item1,EI_CreateItem (font,"Quit",PROJECT_BASE_ID+4,0,0));
- EI_AddToMenu (menu,item1);
- // These menu items are mutually excluded.
- // They also have keyboard equivs. (1,2,3,4)
- // NOTE! if we didn't have a CreateLeave in
- // this menu, we would start with (1<<0),
- // not (1<<1). Wierd but true!
- item1 = EI_CreateItem (font,"Excludes",EXCLUDE_BASE_ID,0,0);
- EI_AddToItem (item1,EI_CreateLeave ());
- tempitem=EI_CreateItem (font,"EXCLUDE 1",EXCLUDE_BASE_ID+1,'1',1);
- tempitem->MutualExclude = ~(1<<1);
- tempitem->Flags &= ~(EI_MENU_TOGGLE);
- EI_AddToItem (item1,tempitem);
- tempitem=EI_CreateItem (font,"EXCLUDE 2",EXCLUDE_BASE_ID+2,'2',1);
- tempitem->MutualExclude = ~(1<<2);
- tempitem->Flags &= ~(EI_MENU_TOGGLE);
- EI_AddToItem (item1,tempitem);
- tempitem=EI_CreateItem (font,"EXCLUDE 3",EXCLUDE_BASE_ID+3,'3',1);
- tempitem->MutualExclude = ~(1<<3);
- tempitem->Flags &= ~(EI_MENU_TOGGLE);
- EI_AddToItem (item1,tempitem);
- tempitem=EI_CreateItem (font,"EXCLUDE 4",EXCLUDE_BASE_ID+4,'4',1);
- tempitem->MutualExclude = ~(1<<4);
- tempitem->Flags &= ~(EI_MENU_TOGGLE);
- EI_AddToItem (item1,tempitem);
- EI_AddToMenu (menu,item1);
- return menu;
- }
- else {
- printf ("can't EI_CreateMenu!\n");
- return NULL;
- }
- }
-
- /*************************************
- PRIVATE: Create_Example.
- This routine is called by the UserWindow routines.
- It passes back a GadBoxPtr to the gadgets wanted.
- *************************************/
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
- EB_GadBoxPtr root,help;
- EB_GadContext gadcon;
-
- gadcon = UserWindow->GadCon;
- root = EB_CreateVertiBox (gadcon);
- EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
- EB_AddLastSon (root,EB_CreateText (gadcon,"Hit the right mouse button."));
- EB_AddLastSon (root,EB_CreateText (gadcon,"This example has menus!"));
- EB_AddLastSon (root,EB_CreateText (gadcon,"Keyboard equivs work with the right amiga key."));
- help=EB_CreateTextAction (gadcon,"Ghost Save as Menu Item",TESTING_ID,EB_FILL_ALL);
- EB_NewPri (help,-1);
- EB_AddLastSon (root,help);
-
-
- EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
- return root;
- }
-
- /**************************************
- PRIVATE: GadgetDown_Example.
- This routine handles the gadget down events passed to the
- Example Control Window.
- **************************************/
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
-
-
- switch (iaddress->GadgetID) {
- case TESTING_ID:
- printf ("Toggling ghosting on Menu item 'Save as'\n");
- ToggleGhost_Menu_Item (PROJECT_BASE_ID+3);
- break;
- }
- }
- /**************************************
- PRIVATE: Menu_Example.
- This routine handles the Menu events passed to the
- Example Control Window.
- **************************************/
- void Menu_Example (UserInputWindowPtr UserWindow, UWORD code) {
-
- switch (code) {
- case PROJECT_BASE_ID+1:
- printf ("Project: Open\n");
- break;
- case PROJECT_BASE_ID+2:
- printf ("Project: Save\n");
- break;
- case PROJECT_BASE_ID+3:
- printf ("Project: Save as...\n");
- break;
- // Here is how to signal a MODAL window to
- // close early.
- case PROJECT_BASE_ID+4:
- printf ("Project: Quit.\n");
- UserWindow->Signals |= SIGNAL_CLOSE;
- break;
- }
- }
-
- /***************************
- Feel free to use these routines in your code. They handle ghosting
- a Menu item for you.
- **************************/
-
- void Ghost_Menu_Item (long code) {
- EI_MenuItemPtr item;
- EI_MenuPtr menu;
-
- if (menu = EI_FindSubMenu (ExampleMenus,code)) {
- if (item = EI_FindMenuItem (menu,code)) {
- if (item->Flags&(EI_MENU_ACTIVE)) {
- EI_OffMenuItem (menu,item);
- }
- }
- }
- }
-
- void UnGhost_Menu_Item (long code) {
- EI_MenuItemPtr item;
- EI_MenuPtr menu;
-
- if (menu = EI_FindSubMenu (ExampleMenus,code)) {
- if (item = EI_FindMenuItem (menu,code)) {
- if (!(item->Flags&(EI_MENU_ACTIVE)) ) {
- EI_OnMenuItem (menu,item);
- }
- }
- }
- }
-
- void ToggleGhost_Menu_Item (long code) {
- EI_MenuItemPtr item;
- EI_MenuPtr menu;
-
- if (menu = EI_FindSubMenu (ExampleMenus,code)) {
- if (item = EI_FindMenuItem (menu,code)) {
- if (!(item->Flags&(EI_MENU_ACTIVE)) ) {
- EI_OnMenuItem (menu,item);
- }
- else {
- EI_OffMenuItem (menu,item);
- }
- }
- }
- }